#!/usr/bin/env bash
set -e

LOG_FILE="/root/result.log"
cur_path=$(pwd)

echo "start to prepare it env"
chmod +x /root/repo/ci-repos/.common_scripts/common.sh
source /root/repo/ci-repos/.common_scripts/common.sh
set_gitee_hosts
prepare_git $1 $2
prepare_conan2 $3 $4
prepare_bingo
prepare_sdk

echo "start to it.........."
cd ${cur_path}
timeout 45m bingo test -it -jit | tee ${LOG_FILE} 2>&1 || die
if [ $? -gt 0 ]; then
  die "ST任务失败"
  exit 1
else
  echo "ST任务成功"
fi

CNT=$(grep -cE '\(=== test failed ===|lua call \[.*\] error' ${LOG_FILE}) ||:
if [ ${CNT} -gt 0 ]; then
  die "IT用例不通过，请在日志中检索==== test failed ======或者lua call .* error 查看详细日志"
  exit 1
else
  CFAILCNT=$(grep -c "FAIL: " ${LOG_FILE})||:
  if [ $CFAILCNT -gt 0 ]; then
    die "C语言IT任务用例不通过，请在日志中搜索FAIL：查询详细日志"
    exit 1
  fi
fi
